<?php
class Admin_model extends CI_Model {
    
    private $table_setting='gpt_setting';
    function __construct()
    {
        parent::__construct();
    }
    //$query->free_result(); 
    
    function select_max($table,$file){
         $this->db->select_max($file);
         $query1 = $this->db->get($table);
         $row = $query1->row(); 
         if(empty($row)){
            return false;
         }else  return $row->id;
    }
    function get_one($table,$where){
        $this->db->where($where);
        $query = $this->db->get($table);
        if($query->num_rows() > 0 ){
            $data = $query->row();
            $query->free_result();
           return $data;
        }else return false;
    }
    function get_number($table,$where='',$limit=''){
        if(!empty($where)){
            $this->db->where($where);
        }
        if(!empty($limit)){
            $this->db->limit($limit);
        }
        $query = $this->db->get($table);
        return $query->num_rows();
    }
    function get_data($table,$where='',$order='',$limit='',$select=''){
        if(!empty($where)){
            $this->db->where($where);
        }
        if(!empty($order)){
            $this->db->order_by($order['truong'],$order['sapxep']);
        }
        if(!empty($limit)){          
            $this->db->limit($limit);           
        }
        if(!empty($select)){
            $this->db->select($select);
        }
        
        $query = $this->db->get($table);
        if($query->num_rows() > 0){
            $data = $query->result();
            $query->free_result();
            return $data;
        }else return false;
    }   
    function check_trung($nd,$table){
        $this->db->where($nd);
        $query = $this->db->get($table);
        if($query->num_rows()>0){
            $query->free_result();
            return true;
        }return false;
    }
    function getall($off = '',$limit = ''){
        $this->db->limit($off,$limit);
        $order = array('point2','asc');
        $this->db->order_by($order); // 'asc' la tang dan ,'desc' là giam dan, 'random'...
        
        $query = $this->db->get('phongkham');
        $data = $query->result_array();
        return $data;
    }
    function numrows(){
        return $this->db->count_all('phongkham');
    }
  
    
}